package org.paradigmshift.timelapse.ui;

import java.awt.Component;
import java.awt.Color;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.plaf.UIResource;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;

@SuppressWarnings( "serial" )
public class FakeTableColumnHeaderRenderer extends DefaultTableCellRenderer implements UIResource {
	
	@Override
	public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) {
		
		if ( table != null ) {
			JTableHeader header = table.getTableHeader();
			if ( header != null ) {
				Color fgColor = null;
				Color bgColor = null;
				
				if ( hasFocus ) {
					fgColor = UIManager.getColor( "TableHeader.focusCellForeground" );
					bgColor = UIManager.getColor( "TableHeader.focusCellBackground" );
				}
				if ( fgColor == null ) fgColor = header.getForeground();
				if ( bgColor == null ) bgColor = header.getBackground();
				
				setForeground( fgColor );
				setBackground( bgColor );
				
				setFont( header.getFont() );
			}
		}
		
		setText( value == null ? "" : value.toString() );
		setIcon( UIManager.getIcon( "Table.naturalSortIcon" ) );
		setBorder( UIManager.getBorder("TableHeader.cellBorder") );
		
		return this;
	}
}
